package com.piece.test;

import com.piece.core.framework.support.response.AjaxResponse;
import com.piece.core.framework.util.security.SecurityUtil;
import com.piece.core.framework.util.string.JsonUtil;
import com.piece.core.message.client.impl.DingTalkSmsClient;
import com.piece.core.message.properties.SmsProperties;
import org.apache.commons.collections.map.LinkedMap;
import org.junit.jupiter.api.Test;

public class MessageTest {

    /**
     * 测试发送钉钉消息
     */
    @Test
    public void sendDingTalk() {
        SmsProperties properties = new SmsProperties();
        properties.setApiKey("696b5d8ead48071237e4aa5861ff08dbadb2b4ded1c688a7b7c9afc615579859");
        properties.setApiSecret("SEC5c4e5ff888bc8a9923ae47f59e7ccd30af1f14d93c55b4e2c9cb094e35aeed67");
        properties.setSignature("芋道");

        try {
            long timestamp = System.currentTimeMillis();
            String secret = properties.getApiSecret();
            String stringToSign = timestamp + "\n" + secret;
            String sign = SecurityUtil.encryptHMAC("HmacSHA256", stringToSign, secret);
        } catch (Exception e) {
            e.printStackTrace();
        }

        DingTalkSmsClient client = new DingTalkSmsClient("芋道", properties, null);
        LinkedMap param = new LinkedMap();
        param.put("username", "username");
        param.put("info", "info");
        AjaxResponse response = client.sendSms("18066666666", null, param);
        System.out.println(JsonUtil.toJson(response));
    }
}
